package com.demo.effective.a2;

/**
 * @author : YU.TAN
 * @date : 2021/11/11 16:05
 */
public class NutritionFacts {

    private int servings;
    private int servingSize;
    private int color;
    private int fat;
    private int sodium;

    private NutritionFacts(Builder builder) {
        servings = builder.servings;
        servingSize = builder.servingSize;
        color = builder.color;
        fat = builder.fat;
        sodium = builder.sodium;
    }

    public static class Builder {
        //Required parameters
        private int servings;
        private int servingSize;

        //Optional parameters
        private int color;
        private int fat;
        private int sodium;

        public Builder(int servings, int servingSize) {
            this.servings = servings;
            this.servingSize = servingSize;
        }

        public Builder color(int val) {
            color = val;
            return this;
        }

        public Builder fat(int val) {
            fat = val;
            return this;
        }

        public Builder sodium(int val) {
            sodium = val;
            return this;
        }

        public NutritionFacts build() {
            return new NutritionFacts(this);
        }

    }
}
